import GComponent = fgui.GComponent;
import GImage = fgui.GImage;
import GRoot = fgui.GRoot;
import RelationType = fgui.RelationType;
import GGraph = fgui.GGraph;

/** 加载 */
export class WaitResult extends GComponent {

    private static _instance: WaitResult
    static get inst() {
        this._instance ??= createView("//gameCommon/WaitResult", WaitResult)
        return this._instance
    }

    static defaultDelay = 1000

    private img: GImage
    private graph: GGraph


    protected override onConstruct() {
        super.onConstruct();
        this.addRelation(GRoot.inst, RelationType.Size)
        this.setSize(GRoot.inst.width, GRoot.inst.height)

        this.img = this.getChild("n0").asImage
        this.graph = this.getChild("n1").asGraph

    }

    show(delay = WaitResult.defaultDelay) {
        this.graph.visible = this.img.visible = false
        GRoot.inst.addChild(this)
        Laya.timer.once(delay, this, this.showContent)
    }

    private showContent() {
        this.graph.visible = this.img.visible = true
    }

    hide() {
        Laya.timer.clear(this, this.showContent)
        this.removeFromParent()
    }

}

